<?php
require("top.ajax.php");
switch($_POST['method']){
        case 'addQuantity':
        $p=new Product($_POST['id_product']);
        $add=$_SESSION['cart']->addQuantity($p);
        $prices = array('quantity'=>$add['quantity'], "total"=>$_SESSION['cart']->getTotal(), "nbProducts"=>$_SESSION['cart']['NbProducts']);
        echo json_encode($prices);
        break;

    case 'subQuantity':
        $p=new Product($_POST['id_product']);
        $sub=$_SESSION['cart']->subQuantity($p);
        $prices = array('quantity'=>$sub['quantity'], "total"=>$_SESSION['cart']->getTotal(), "nbProducts"=>$_SESSION['cart']['NbProducts']);
        echo json_encode($prices);
        break;

    case 'deleteProduct':
       $delVendor = $_SESSION['cart']->deleteProduct($_POST['id_vendor'], $_POST['id_product']);
       if(sizeof($_SESSION['cart']['vendors'])==0) $datas=array("cart"=>'empty');
        else $datas = array("cart"=>'notempty', "total"=>$_SESSION['cart']->getTotal(), "nbProducts"=>$_SESSION['cart']['NbProducts']);
        echo json_encode($datas);
        break;


    case 'display':

        $tpl->display("ajax/floating_cart.tpl");
        break;
}

?>